package com.westos.userauth.web;

import com.westos.userauth.dto.UserInfoDTO;
import com.westos.userauth.dto.UserLoginDTO;
import com.westos.userauth.dto.UserLoginStatueDTO;
import com.westos.userauth.service.LoginService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/userLogin")
public class LoginController {

    @Autowired
    private LoginService loginService;

    @ApiOperation("用户登录")
    @PostMapping("/login")
    public ResponseEntity<UserLoginStatueDTO> login(UserLoginDTO userLoginDTO){
        UserLoginStatueDTO userLoginStatueDTO = loginService.login(userLoginDTO);
        return new ResponseEntity<>(userLoginStatueDTO, HttpStatus.OK);
    }
    @ApiOperation("查询用户登录信息")
    @GetMapping("/userInfo")
    public ResponseEntity<UserInfoDTO> getLoginedUserinfo(@RequestParam("userId") String userId){
        UserInfoDTO loginedUserinfo = loginService.getLoginedUserinfo(userId);
        return new ResponseEntity<>(loginedUserinfo,HttpStatus.OK);
    }
}
